import 'package:boss/ui/page/marketing/coupon/couponDetail/coupon_detail_page.dart';
import 'package:boss/ui/page/marketing/coupon/couponList/provider/coupon_list_provider.dart';
import 'package:boss/ui/widget/center_title_app_bar.dart';
import 'package:boss/ui/widget/label_button.dart';
import 'package:flutter/material.dart';
import 'package:hi_common/hi_common.dart';
import 'package:provider/provider.dart';
import 'package:router/annotation.dart';

import 'widget/coupon_list_browser.dart';

@RouterConfig(CouponListPage.pageName)
class CouponListPage extends StatefulWidget {
  static const String pageName = '/CouponListPage';

  @override
  _CouponListPageState createState() => _CouponListPageState();
}

class _CouponListPageState extends BaseState<CouponListPage> {
  _CouponListPageState() : super(CouponListPage.pageName);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CenterTitleAppBar(
        title: '优惠券管理',
        actions: <Widget>[
          LabelButton(
            title: '+新增优惠券',
            padding: EdgeInsets.only(left: 8, top: 2, bottom: 2),
            onTap: () async {
              await Navigator.pushNamed(context, CouponDetailPage.pageName);

              final provider = Provider.of<CouponListProvider>(context, listen: false);
              provider.queryInvalidCouponList();
              provider.queryValidCouponList();
            },
          ),
        ],
      ),
      body: CouponListBrowser(),
    );
  }
}
